package com.intellagric.service.iftmonitor.Impl.ift_equipment_channel;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.IftEquipmentChannelMapper;
import com.intellagric.module.iftmonitor.EquipmentChannelVo;
import com.intellagric.pojo.IftEquipmentChannel;
import com.intellagric.pojo.IftEquipmentChannelExample;
import com.intellagric.service.iftmonitor.ift_equipment_channel.EquipmentChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/12/13
 * @DESC： 采集设备通道服务
 */
@Service
public class EquipmentChannelServiceImpl implements EquipmentChannelService {

    @Autowired
    private IftEquipmentChannelMapper equipmentChannelMapper;

    /**
     * 添加采集设备通道
     * @param equipmentChannel
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addEquipmentChannel(IftEquipmentChannel equipmentChannel) {
        if (equipmentChannelMapper.insertSelective(equipmentChannel) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除采集设备通道
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteEquipmentChannel(String id) {
        if (equipmentChannelMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 编辑采集设备通道
     * @param equipmentChannel
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editEquipmentChannel(IftEquipmentChannel equipmentChannel) {
        if (equipmentChannelMapper.updateByPrimaryKeySelective(equipmentChannel) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询采集设备通道
     * @param id
     * @return ResponseMessage
     */
    @Override
    public IftEquipmentChannel getEquipmentChannelById(String id) {
        return equipmentChannelMapper.selectByPrimaryKey(id);
    }

    /**
     * 多条件查询采集设备通道
     * @param equipmentChannelVo
     * @return ResponseMessage
     */
    @Override
    public LayuiDataGridResult getEquipmentChannelListByVo(EquipmentChannelVo equipmentChannelVo) {
        IftEquipmentChannelExample equipmentChannelExample = new IftEquipmentChannelExample();
        equipmentChannelExample.setOrderByClause("channel_id");
        equipmentChannelExample.createCriteria().andEquipmentIdEqualTo(equipmentChannelVo.getEquipmentId());
        List<IftEquipmentChannel> equipmentChannelList = equipmentChannelMapper.selectByExample(equipmentChannelExample);
        return LayuiDataGridResult.success().add(equipmentChannelList,equipmentChannelList.size());
    }

    /**
     * 查询采集设备通道列表
     * @return ResponseMessage
     */
    @Override
    public LayuiDataGridResult getEquipmentChannelList() {
        IftEquipmentChannelExample equipmentChannelExample = new IftEquipmentChannelExample();
        equipmentChannelExample.createCriteria().andRelChannelIdIsNotNull();
        List<IftEquipmentChannel> equipmentChannelList = equipmentChannelMapper.selectByExample(equipmentChannelExample);
        return LayuiDataGridResult.success().add(equipmentChannelList,equipmentChannelList.size());
    }

}
